Developing Serverless Solutions on AWS - Live Session Guide
This module covers asynchronous event-driven patterns using Amazon EventBridge and Amazon SNS to build loosely coupled serverless architectures.
In async invocation, the caller doesn't wait for the function to finish. Lambda queues the event and processes it independently.
| Aspect | Synchronous | Asynchronous |
|---|---|---|
| Caller behavior | Waits for response | Gets 202 Accepted immediately |
| Retry behavior | Caller retries | Lambda retries (0-2 times) |
| Error handling | Error returned to caller | Dead-letter queue (DLQ) or on-failure destination |
| Sources | API Gateway, SDK invoke | EventBridge, SNS, S3, CloudWatch Events |
| Pattern | How It Works | Best For |
|---|---|---|
| Client Polling | Client periodically checks status endpoint | Simple, stateless clients |
| Webhook | Server calls back to a client-provided URL | Server-to-server notifications |
| WebSocket | Persistent connection, server pushes updates | Real-time UIs, chat, dashboards |
A serverless event bus that connects applications using events from AWS services, SaaS apps, and custom sources.
| Concept | Description |
|---|---|
| Event Bus | Router that receives events and routes them to targets. Default bus + custom buses. |
| Event | JSON object representing a state change (source, detail-type, detail) |
| Rule | Matches incoming events using event patterns and routes to targets |
| Target | Destination for matched events (Lambda, SQS, Step Functions, API Gateway, etc.) |
| Event Pattern | JSON filter that matches event fields (content-based filtering) |
| Archive | Store events for replay later (debugging, reprocessing) |
| Replay | Re-send archived events to the bus (disaster recovery) |
| Pipes | Point-to-point integration with filtering, enrichment, transformation |
{
"version": "0",
"id": "12345678-1234-1234-1234-123456789012",
"source": "com.mycompany.orders",
"detail-type": "Order Created",
"account": "123456789012",
"time": "2024-06-15T10:30:00Z",
"region": "us-west-2",
"detail": {
"orderId": "ORD-987654",
"department": "billing",
"amount": 149.99,
"customer": "user12345"
}
}
// Match orders from billing or fulfillment departments
{
"source": ["com.mycompany.orders"],
"detail-type": ["Order Created"],
"detail": {
"department": ["billing", "fulfillment"]
}
}
Lambda | SQS | SNS | Step Functions | Kinesis | API Gateway | CloudWatch Logs | CodePipeline | ECS Task | Redshift | API Destinations (any HTTP endpoint) | Another Event Bus (cross-account/region)
Fully managed pub/sub messaging service for fan-out to multiple subscribers.
| Concept | Description |
|---|---|
| Topic | A communication channel - publishers send messages to it |
| Publisher | Produces messages and sends them to a topic |
| Subscriber | Receives messages from a topic (Lambda, SQS, HTTP, email, SMS) |
| Filter Policy | JSON filter on message attributes - subscribers only get matching messages |
| Standard Topic | Best-effort ordering, at-least-once delivery, massive throughput |
| FIFO Topic | Strict ordering, exactly-once delivery, 300 msg/sec (or 3000 with batching) |
// Subscription filter policy - only receive "billing" department messages
{
"department": ["billing"],
"amount": [{"numeric": [">=", 100]}]
}
One SNS topic can fan-out to multiple independent microservices (search indexing, backup, analytics, notifications) - each runs independently and can fail without affecting others.
| Feature | EventBridge | Amazon SNS |
|---|---|---|
| Pattern | Event bus (routing) | Pub/Sub (fan-out) |
| Sources | 200+ AWS services, SaaS, custom | AWS services, custom publishers |
| Targets | 20+ (Lambda, SQS, Step Functions, API Destinations) | Lambda, SQS, HTTP, Email, SMS, mobile push |
| Filtering | Content-based (event pattern - complex matching) | Message attribute filtering |
| Fan-out | 5 targets per rule (use multiple rules) | 12.5M subscriptions per topic |
| Ordering | No ordering guarantee | FIFO topics available |
| Replay | Yes (archive + replay) | No built-in replay |
| Schema | Schema registry + discovery | No schema management |
| Cross-account | Cross-account/region event bus | Cross-account topic subscriptions |
| Throughput | Region-dependent limits | Nearly unlimited (Standard) |
| DLQ support | Yes (per target) | Yes (can BE the DLQ for Lambda) |
aws events create-event-bus --name demo-orders-bus --region us-west-2
# handler.py
import json
def handler(event, context):
print(f"Received event: {json.dumps(event)}")
order_id = event.get("detail", {}).get("orderId", "unknown")
dept = event.get("detail", {}).get("department", "unknown")
return {"statusCode": 200, "body": f"Processed order {order_id} from {dept}"}
aws events put-rule \
--name billing-orders-rule \
--event-bus-name demo-orders-bus \
--event-pattern '{
"source": ["com.mycompany.orders"],
"detail": {
"department": ["billing"]
}
}' \
--state ENABLED
aws events put-targets \ --rule billing-orders-rule \ --event-bus-name demo-orders-bus \ --targets "Id"="lambda-target","Arn"="arn:aws:lambda:us-west-2:ACCOUNT:function:order-processor"
aws events put-events --entries '[
{
"Source": "com.mycompany.orders",
"DetailType": "Order Created",
"Detail": "{\"orderId\":\"ORD-001\",\"department\":\"billing\",\"amount\":250}",
"EventBusName": "demo-orders-bus"
}
]'
aws logs tail /aws/lambda/order-processor --follow
aws events put-events --entries '[
{
"Source": "com.mycompany.orders",
"DetailType": "Order Created",
"Detail": "{\"orderId\":\"ORD-002\",\"department\":\"shipping\",\"amount\":50}",
"EventBusName": "demo-orders-bus"
}
]'
# This event won't match the rule (department != "billing")
Developing Serverless Solutions on AWS - Module 5 | Live Session Guide
Last updated: June 2026